<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="$attrs.Title||'新增任务'" ref="userManageEdit" width="1200"
                 height="550" @save="save" :saveLoading="saveLoading">
      <template slot="body">
        <el-row>
          <el-col :span="24">
            <vxe-grid
                ref="gridTable"
                border
                resizable
                export-config
                import-config
                keep-source
                style="height: calc(100vh - 140px)"
                height="auto"
                tableId="data-table"
                id="toolbar_demo_1"
                :loading="tableLoading"
                :toolbar="tableToolbar"
                :pager-config="pagerConfig"
                :data="tableData">
              <!-- 工具栏按钮插槽 -->
              <vxe-table-column type="radio" width="40"></vxe-table-column>
              <template slot="buttons">
                <div style="float: right;margin-right: 12px;">
                  <el-button icon="el-icon-circle-plus" size="medium" circle title="新建用例"></el-button>
                </div>
              </template>
              <vxe-table-column title="编号" align="center" width="300">
                <template v-slot="{ row }">
                  <span>{{row.Id}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="状态" align="center" width="100">
                <template v-slot="{ row }">
                  <span>{{row.Status}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="标题" align="center">
                <template v-slot="{ row }">
                  <span>{{row.Name}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="版本" align="center" width="100">
                <template v-slot="{ row }">
                  <span>{{row.Vesionno}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="维护人" align="center" width="100">
                <template v-slot="{ row }">
                  <span>{{row.Acceptname}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="重要程度" align="center" width="100">
                <template v-slot="{ row }">
                  <span>{{row.Degree}}</span>
                </template>
              </vxe-table-column>
              <vxe-table-column title="用例类型" align="center" width="100">
                <template v-slot="{ row }">
                  <span>{{row.Type}}</span>
                </template>
              </vxe-table-column>
            </vxe-grid>
          </el-col>
        </el-row>
      </template>
    </dialog-edit>
  </div>
</template>

<script>
import dialogEdit from '@/components/element/dialogEdit'
import dymForm from '@/components/element/dymForm'
import testDialog from '@/page/ProjectManage/modules/proTest/testDialog'
import testCaseApi from "@/api/testCaseApi";

export default {
  name: "taskAddDialog",
  components: {
    dialogEdit,
    dymForm,
    testDialog
  },
  props: {
    visible: {
      type: Boolean,
      default() {
        return false;
      }
    },
    preFormData: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  computed: {
    dialogVisible: {
      get: function () {
        return this.visible
      },
      set: function (value) {
        this.$emit('update:visible', value)
      }
    }
  },
  data () {
    return {
      saveLoading: false,
      testDialogVisible: false,
      caseForm: {},
      editVisible: false,
      tableData: [
        {
          UserrealName: 'dadasdasas'
        }
      ],
      tableToolbar: {
        refresh: {query: this.getDataList},
      },
      pagerConfig: {
        currentPage: 1,
        pageSize: 15,
        total: 0,
        pagerCount: 7,
        pageSizes: [10,15,20,50,100]
      },
      tableLoading: false,
      queryParas: {
        p: 1,
        pageoffset: 15,
      }
    }
  },
  methods: {
    save () {
      let a = this.$refs.gridTable.getRadioRecord()
      if (a) {
        this.$emit('selectData', a)
        this.dialogVisible = false
      }
    },
    getDataList () {
      this.tableLoading = true
      this.queryParas.id = this.preFormData.Projectid
      console.log(this.queryParas)
      testCaseApi.getPageCase(this.queryParas).then(res => {
        if (res && res.Modules) {
          const { Modules, Total } = res
          this.tableData = Modules;
          this.pagerConfig.total = Total
        } else {
          this.tableData = []
        }
      }).finally(() => {
        this.tableLoading = false
      })
    },
  },
  watch: {
    dialogVisible: {
      handler (n, o) {
        if (n) {
          this.getDataList()
        }
      }
    }
  }
}
</script>

<style scoped>
.dymForm >>> .el-date-editor {
  width: 100%;
}
</style>